import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {
    public static List <List<Integer>> func(int[] arr){
        Arrays.sort(arr);
        List <List<Integer>> ret = new ArrayList<>();
        for (int i = 0; i < arr.length; ) {
            if (arr[i] > 0){
                break;
            }
            int left = i+1;
            int right = arr.length-1;
            while (left < right){
                if(arr[left]+arr[right] > -arr[i]){
                    right--;
                }else if(arr[left]+arr[right]< -arr[i]){
                    left++;
                }else{
                    ret.add(new ArrayList<Integer>(Arrays.asList(arr[i],arr[left],arr[right])));
                    left++;
                    right--;
                    while (left<right && arr[left] == arr[left-1]) left++;
                    while(left<right && arr[right] == arr[right+1]) right--;
                }
            }
            i++;
            while(i<arr.length && arr[i]==arr[i-1]) i++;
        }
        return  ret;
    }
    public static void main(String[] args) {
        int[] arr = new int[]{-1,0,1,2,-1,-4};
        List <List<Integer>> ret = func(arr);
        System.out.println(ret);
    }
}